import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class UdpExp02 {
    public static void main(String[] args) throws InterruptedException {
        byte[] receiveByte = new byte[8192];
        DatagramSocket ds = null;
        try {
            ds = new DatagramSocket(8954);
        } catch (SocketException e) {
            e.printStackTrace();
        }
        DatagramPacket dp = new DatagramPacket(receiveByte,receiveByte.length);
        System.out.println("等待接收数据...");
        try {
            ds.receive(dp);
        } catch (IOException e) {
            e.printStackTrace();
        }
        while (true){
            String str1 = new String(dp.getData(),0,dp.getLength())+"from"+dp.getAddress().getHostAddress()+":"+dp.getPort()+"\n";
            Thread.sleep(1000);
            System.out.println(str1);
        }
    }
}
